<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitereview
 * @copyright  Copyright 2012-2013 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: index.tpl 6590 2013-04-01 00:00:00Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
 ?>

<?php if($this->createAllow == 1):?>
  <button class="sr_review_button" onclick="writeAReview('create');"><?php echo $this->translate("Write a Review") ?></button>
<?php elseif($this->createAllow == 2):?>
  <button class="sr_review_button" onclick="writeAReview('update');"><?php echo $this->translate("Update your Review") ?></button>
<?php endif;?>
  
<script type="text/javascript">
  function writeAReview(option){
    <?php if($this->listing_profile_page): ?>
      if($('main_tabs') && $('main_tabs').getElement('.tab_layout_sitereview_user_sitereview')){
        if($('sitereview_create') && $('main_tabs').getElement('.tab_layout_sitereview_user_sitereview').hasClass('active')){
          window.location.hash = 'sitereview_create';
          return;
        } else if($('sitereview_update') && $('main_tabs').getElement('.tab_layout_sitereview_user_sitereview').hasClass('active')){
          window.location.hash = 'sitereview_update';
          return;
        } 
        tabContainerSwitch($('main_tabs').getElement('.tab_layout_sitereview_user_sitereview'));
          <?php if($this->contentDetails && isset ($this->contentDetails->params['loaded_by_ajax']) && $this->contentDetails->params['loaded_by_ajax']): ?>
        var params = {
          requestParams :<?php echo json_encode($this->contentDetails->params) ?>,
          responseContainer :$$('.layout_sitereview_user_sitereview')
        }

        params.requestParams.content_id = '<?php echo $this->contentDetails->content_id ?>';
        en4.sitereview.ajaxTab.sendReq(params);
        <?php endif; ?>
        if(option == 'create') {
          (function(){
            window.location.hash = 'sitereview_create';
          }).delay(3000);
        } else if(option == 'update') {
          (function(){
            window.location.hash = 'sitereview_update';
          }).delay(3000);
        }
      } else {
        if(option == 'create') {
// 						(function(){
            window.location.hash = 'sitereview_create';
// 						}).delay(3000);
        } else if(option == 'update') {
// 						(function(){
            window.location.hash = 'sitereview_update';
// 						}).delay(3000);
        }
      }
      <?php else:?>
      window.location.href="<?php echo $this->sitereview->getHref(); ?>";
      <?php endif;?>
    }
  </script>